<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../base_path.jsp" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="description" content="">

    <link rel="stylesheet" type="text/css" href="<%=basePath%>/lib/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <link type="text/css" rel="stylesheet" href="<%=basePath%>/lib/bootstrap-select/css/bootstrap-select.min.css"/>
	<link type="text/css" rel="stylesheet" href="<%=basePath%>/lib/bootstrap-switch/css/bootstrap3/bootstrap-switch.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen"
          href="<%=basePath%>/lib/jqgrid/5.2.1/css/ui.jqgrid-bootstrap.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/lib/lobibox/css/lobibox.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/css/mycss.css"/>

    <title>账户管理</title>
	    <style>
	        .header-right {
	            position: absolute;
	            bottom: 16px;
	            right: 0px;
	        }
	
	        .page-header {
	            position: relative;
	        }
	
	        .block-head {
	            position: relative;
	            line-height: 66px;
	            font-size: 15px;
	            color: #545b66;
	            height: 23px;
	            display: inline-block;
	        }
	
	        .head-search {
	            position: absolute;
	            top: 2px;
	            right: 2px;
	            width: 280px;
	            height: 36px;
	            border-radius: 5px;
	            border: 1px solid #bcbec5;
	        }
	
	        .head-search.empty_input input {
	            height: 34px;
	            width: 240px;
	            border: none;
	            border-radius: 5px;
	            padding-left: 10px;
	            color: #757b84;
	            font-size: 14px;
	            background: transparent;
	        }
	
	        .head-search input {
	            height: 34px;
	            width: 206px;
	            border: none;
	            border-radius: 5px;
	            padding-left: 10px;
	            color: #757b84;
	            font-size: 14px;
	            background: transparent;
	        }
	
	        .search-btn {
	            float: right;
	            width: 26px;
	            height: 34px;
	            padding: 8px;
	            cursor: pointer;
	            padding-left: 0px;
	        }
	
	        .clear-btn {
	            float: right;
	            width: 26px;
	            height: 34px;
	            padding: 8px;
	            cursor: pointer;
	            padding-left: 0px;
	        }
	
	        .empty_input .clear-btn {
	            display: none;
	        }
	    </style>
	
</head>
<body>
<div class="navbar-fixed-top">
    <div class="breadcrumb">
        <span>账户管理</span>/
        <span class="active">账户管理</span>
        <span class="pull-right" title="刷新">
            <div class="btn-refresh" onclick="location.replace(location.href);">
            	<img src="<%=basePath%>/images/refresh.png" >
            </div>
        </span>
    </div>
</div>
<div class="container-fluid">
	<div class="container-fluid-main">
    <div class="page-header">
        <h3>账户管理</h3>
		<div class="header-right">
            <button class="btn btn-primary" id="btn_create_account">创建账户</button>
        </div>
    </div>

    <div class="panel panel-default panel-default-sample">
        <div class="panel-body">
            <div>
                <form id="from_select_item">
                    <div class="row">
                        <div class="col-sm-11">
                            <div class="col-lg-4 col-sm-6 margin-top-10">
                                <label class="control-label col-md-3 padding-top-5" for="txt_role_power">用户名：</label>
                                <div class="col-md-9">
                                    <select id="txt_user_name" class="selectpicker form-control input-sm"
                                            name="txt_user_name" data-actions-box="true">
                                        <option value="" selected >请选择</option>
                                        <c:forEach var="item" items="${userList}">
                                            <option value="${item.username}">${item.username}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-4 col-sm-6 margin-top-10">
                                <label class="control-label col-md-3 padding-top-5" for="txt_role_power">角色：</label>
                                <div class="col-md-9">
                                    <select id="txt_role_power" class="selectpicker form-control input-sm"
                                            name="txt_role_power" data-actions-box="true">
                                        <option value="" selected >请选择</option>
                                        <c:forEach var="item" items="${roleList}">
                                            <option value="${item.id}">${item.roleName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-4 col-sm-6 margin-top-10">
                                <label class="control-label col-md-3 padding-top-5" for="txt_org">所属组织：</label>
                                <div class="col-md-9">
                                    <shiro:hasAnyRoles name="role_super_admin,role_admin">
                                        <select id="txt_org" class="selectpicker form-control input-sm"
                                                data-live-search="true"
                                                name="txt_org" data-live-search-placeholder="Search" data-actions-box="true"
                                                title="请选择">
                                            <option value="" selected >请选择</option>
                                            <c:forEach var="item" items="${orgList}">
                                                <option value="${item.id}">${item.orgName}</option>
                                            </c:forEach>
                                        </select>
                                    </shiro:hasAnyRoles>
                                    <shiro:hasAnyRoles name="dep_leader,quality_specialist,analysis_specialist,call_specialist">
                                        <select id="txt_org" class=" form-control input-sm"
                                                name="txt_org" disabled>
                                            <c:forEach var="item" items="${orgList}">
                                                <option value="${item.id}" selected>${item.orgName}</option>
                                            </c:forEach>
                                        </select>
                                    </shiro:hasAnyRoles>
                                </div>
                            </div>

                            <div class="col-lg-4 col-sm-6 margin-top-10">
                                <label class="control-label col-md-3 padding-top-5"
                                       for="txt_state_account">账户状态：</label>
                                <div class="col-md-9">
                                    <select id="txt_state_account" class="selectpicker form-control input-sm"
                                            title="请选择"
                                            name="txt_state_account" data-actions-box="true">
                                        <option value="" selected >请选择</option>
                                        <option value="0">启用</option>
                                        <option value="1">停用</option>
                                        <%--<option value="2">禁用</option>--%>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-4 col-sm-6 margin-top-10">
                                <label class="control-label col-md-3 padding-top-5" for="txt_business">所属业务：</label>
                                <div class="col-md-9">
                                    <select id="txt_business" class="selectpicker form-control input-sm"
                                            data-live-search="true" title="请选择"
                                            name="txt_business" data-live-search-placeholder="Search"
                                            data-actions-box="true">
                                        <option value="" selected >请选择</option>
                                        <c:forEach var="item" items="${allTemplateList}">
                                            <option value="${item.id}">${item.templateName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-1">
                            <button  class="btn btn-primary btn-sm margin-top-10 sm-right-margin" onclick="refreshJQGrid();return false;">查询</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <table id="AccountJQGrid"></table>
    <div style="height: 40px" id="AccountJQGridPager"></div>
	</div>
    <div class="modal fade" id="modal_modify_account" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改账户信息</h4>
                </div>
                <div class="modal-body">
                    <div class="container-fluid container-fluid-w" style="background: #FFF;width: 90%;margin-top: 20px;">
                        <form id="form_modify_pwd" class="form-horizontal" style="padding: 20px;">
                        <div class="form-group">
                            <div>
                                <label class="col-md-3 control-label">用户名</label>
                                <div class="col-md-8">
                                    <p class="form-control-static" id="userName">张三</p>
                                    <p class="form-control-static hide" id="userId">张三</p>
                                </div>
                            </div>

                        </div>
                        <div class="form-group">
                            <label for="txt_account_passwd" class="col-md-3 control-label">密码</label>
                            <div class="col-md-8">
                                <button class="btn btn-default" id="showChangepwd">修改密码</button>
                            </div>
                        </div>
                        <div class="form-group changePwd hide">
                            <label for="txt_account_passwd" class="col-md-3 control-label">修改密码</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control input-sm" id="txt_account_passwd"
                                       name="txt_account_passwd" placeholder="请输入新密码" maxlength="30" autocomplete="off">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group confirmPwd hide">
                            <label for="txt_confirm_passwd" class="col-md-3 control-label">确认密码</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control input-sm" id="txt_confirm_passwd"
                                       name="txt_confirm_passwd" placeholder="请确认密码" maxlength="30" autocomplete="off">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">
                                <label class="text-danger" style="margin-right: 5px">*</label>角色</label>
                            <div class="col-md-8">
                                <c:forEach var="item" items="${roleList}">
                                    <label class="radio-inline ${item.id eq '2' ? 'yuAdmin': 'NotYuAdmin'}">
                                        <input type="radio" name="inlineRadioOptions" value="${item.id}"> ${item.roleName}
                                    </label>
                                </c:forEach>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <%--<div class="form-group">--%>
                        <%--<label for="txt_myorg" class="col-md-3 control-label">--%>
                        <%--<label class="text-danger" style="margin-right: 5px">*</label>所属组织</label>--%>
                        <%--<div class="col-md-6">--%>
                        <%--<select id="txt_myorg" class="selectpicker form-control input-sm" name="txt_myorg"--%>
                        <%--data-live-search="true" title="请选择"--%>
                        <%--data-live-search-placeholder="Search" data-actions-box="true">--%>
                        <%--<c:forEach var="item" items="${orgList}">--%>
                        <%--<option value="${item.id}">${item.orgName}</option>--%>
                        <%--</c:forEach>--%>
                        <%--</select>--%>
                        <%--<span class="help-block"></span>--%>
                        <%--</div>--%>
                        <%--</div>--%>

                        <div class="form-group">
                            <label class="col-md-3 control-label">创建时间</label>
                            <div class="col-md-8">
                                <p class="form-control-static" id="createTime">1998-78-98</p>
                            </div>
                        </div>
                        <div class="form-group text-c">
                                <button type="submit" class="btn btn-primary btn-sm">提交</button>
                        </div>
                    </form>
                    </div>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="modal_create_account" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 模态框（Modal） -->

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="<%=basePath%>/lib/jquery/1.11.0/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap/3.3.7/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/i18n/defaults-zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/jquery.validate_1.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootbox/bootbox.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jqgrid/5.2.1/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/jqgrid/5.2.1/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/lobibox.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/messageboxes.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/notifications.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>

<script type="text/javascript">
    var fmp = null;
    var AccountJQGriddata = [];
	var create_layer;
    $(function () {
        $.jgrid.defaults.responsive = true;
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#AccountJQGrid").jqGrid({
            height: 434,
            autowidth: true,
            shrinkToFit: true, /*  autoScroll: false, *//*forceFit: true, */
            colNames: ["主键", "用户名", "权限编号", "角色", "组织编号", "所属组织", "组织状态", "账户状态", "操作"],
            colModel: [
                {name: "user_id", index: "user_id", key: true, hidden: true},
                {name: "u_name", index: "u_name", align: "left", editable: true},
                {name: "role_id", index: "role_id", hidden: true},
                {name: "role_name", index: "role_name", autowidth: true, align: "left"},
                {name: "org_id", index: "org_id", hidden: true},
                {name: "org_name", index: "org_name", autowidth: true, align: "left"},
                {name: "org_status", index: "org_status", hidden: true},
                {name: "status", index: "status", autowidth: true, align: "left"},
                {name: "edit", index: "edit", autowidth: true, align: "left",hidden: function() {
                        <shiro:hasPermission name="guanlizhanghu">
                        return false
                        </shiro:hasPermission>
                        return true
                    }()}
            ],
            pager: "#AccountJQGridPager",
            viewrecords: true,
            hidegrid: false,
            multiselect: false,
            url: "<%=basePath %>/account/fetchUserInfoJQGridDataByConditions.do",
            datatype: 'json',
            rownumbers: true,
            rowNum: 30,
            rowList: [15, 30, 50],
            jsonReader: {
                root: "dataList", page: "currPage", total: "totalPages",          //   很重要 定义了 后台分页参数的名字。
                records: "totalCount", repeatitems: false, id: "userId"
            },
            loadComplete: function (data) {
                // 自动调整高度
                AccountJQGriddata = data;
                //console.log(data)
                var resCount = data.records;
                var tableHeight = resCount * 30 + 40;
                $("#gbox_AccountJQGrid .ui-jqgrid-bdiv").css(
                    "cssText",
                    "height: " + tableHeight + "px!important;");
            },
            gridComplete: function (a, b, c) {         // 数据加载完成后 添加 采购按钮
				$("#AccountJQGrid").jqGrid('setLabel', 'rn', '序号', {'text-align': 'center', 'font-size': '12px'}, '');
                var ids = jQuery("#AccountJQGrid").jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var id = ids[i];
                    var rowData = jQuery("#AccountJQGrid").jqGrid('getRowData', id);
                    var duration = secondFormat(rowData.duration);
                    jQuery("#AccountJQGrid").jqGrid('setRowData', ids[i], {duration: duration});
                    // 设置呼叫状态显示
//                    console.log(rowData);
                    var orgId = rowData.org_id, orgStatus = rowData.org_status, status = rowData.status, roleId = rowData.role_id;
                    var statusHtml = "";
					var editBtn = "<img src='<%=basePath%>/images/table/edit.png' alt='修改' style='cursor: pointer;margin-right:5px' onclick='editAccount(this, " + id + ")'>"
                    if (orgId = 0) {
                        // 管理员
                        if (status == 1) {
                            statusHtml = "<span class='label label-info'>停用</span>";

								editBtn += "<img src='<%=basePath%>/images/table/on.png' alt='启用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ", " + orgId + ", " + roleId + ")'>"
                        } else if (status == 0) {
                            statusHtml = "<span class='label label-success'>启用</span>";
							editBtn += "<img src='<%=basePath%>/images/table/off.png' alt='停用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ")'>"
                        }
                    } else {
                        // 组织及内部人员
                        if (status == 1) {
                            statusHtml = "<span class='label label-info'>停用</span>";
                            editBtn += "<img src='<%=basePath%>/images/table/on.png' alt='启用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ", " + orgId + ", " + roleId + ")'>"
                        } else if (status == 0) {
                            statusHtml = "<span class='label label-success'>启用</span>";
                            editBtn += "<img src='<%=basePath%>/images/table/off.png' alt='停用' style='cursor: pointer;' onclick='stopOrganize(this, " + id + ")'>"
                        }
                    }
                    jQuery("#AccountJQGrid").jqGrid('setRowData', ids[i], {edit: editBtn, status: statusHtml});
                }
            }
        });

        $("#showChangepwd").on("click", function (e) {
            $(this).closest(".form-group").hide();
            $(".changePwd,.confirmPwd").removeClass("hide");
            e.preventDefault();
            e.stopPropagation();
        })

//        $("#updateOrganize").on("click", editAccount);
//        $('#txt_myorg').on('changed.bs.select',txt_myorg_cbs)

//        $('.modal #txt_business_template').on('show.bs.select', function (e) {
//            if (isEmpty($('.modal #txt_myorg').val())) {
//                    myNotify("error", "", "请先选择所属组织");
//            }
//        })

        $('.modal .selectpicker').on('hide.bs.select', function (e) {
            $(this).focusout();
            if ($(this).val() == null || $('.modal #txt_myorg').val() == "") {
                $(this).addClass("has-error").siblings(".btn").addClass("redBorder");
            } else {
                $(this).removeClass("has-error").siblings(".btn").removeClass("redBorder");
            }
        });
		
		$("#btn_create_account").click(function () {
            $("#modal_create_account").modal({
                backdrop: false,
                keyboard: false,
                remote: '<%=basePath %>/account/showUserCreatePage.do'
            });
			<%--layer.open({--%>
			  <%--type: 2,--%>
			  <%--title: '创建账户',--%>
			  <%--shadeClose: false,--%>
			  <%--shade: 0,--%>
			  <%--area: ['700px', '480px'],--%>
			  <%--content: '<%=basePath %>/account/showUserCreatePage.do', //iframe的url--%>
			  <%--success: function(layero, index) {--%>
				<%--create_layer = index--%>
			  <%--}--%>
			<%--}); --%>
		    
		});
		
		$("#modal_create_account").on("hidden.bs.modal", function() {
		    $(this).removeData("bs.modal");
		    $(this).find(".modal-content").children().remove();
            location.replace(location.href);
		});
        $("#modal_modify_account").on("hidden.bs.modal", function() {
//            $(this).removeData("bs.modal");
//            $(this).find(".modal-content").children().remove();
            location.replace(location.href);
        });
//        var  $txt_myorg=$("#txt_myorg");
        $("input[type='radio'][name='inlineRadioOptions']").change(function () {
            //账户修改弹出框  根据不同人员权限  来显示或设置不可编辑   所属组织和业务模板
            //2是域管理员 3是管理员
            var yuAdmin="2",nAdmin="3"
            console.log(activeUser,"-------------")
            if(this.value == yuAdmin){
                //根据是否是域管理员 来显示组织和业务模板

            }else{

            }

            if(activeUser.role_id == yuAdmin){
                //当给域管理员降级时 所有的组织和业务模板均可操作

//                $txt_myorg.prop("disabled",false).blur();
//                if(this.value == nAdmin){
//
//                }else{
//
//                }

            }else{

                if(this.value != yuAdmin){
                    //根据是否是域管理员 来确定业务模板是否可操作
                    if(this.value == nAdmin){
                        //管理员 业务模板不可编辑

                    }else{

                        if(activeUser.role_id - 3 >0) {
                            //根据修改人员的当前职称来确定【当是管理员以下权限时（不含管理员）】来给修改模板附默认值

                        }else{
                            //管理员以下人员  根据分配的业务模板来显示 可编辑

                        }

                    }
                }
            }

        })
        $("#form_modify_pwd").submit(function (event) {
            //修改操作提交数据
            if ($("#form_modify_pwd").valid()) {
                var formData = new FormData(this);
                var password = $.trim($("#txt_account_passwd").val());
                if (password.length > 0) {
                    formData.append("password", password);
                }
                formData.append("userId", $("#userId").html());
                var roleId=$("input[name='inlineRadioOptions'][type='radio']:checked").val();
                formData.append("roleId",roleId);
//                if(roleId != "2"){
//                    formData.append("orgId", $("#txt_myorg").val());
//                }
                $.ajax({
                    url: '<%=basePath%>/account/userModify.do',
                    type: 'POST',
                    data: formData,
                    async: false,
                    // 这两个参数需要被定义，否则报错
                    contentType: false,
                    processData: false,
                    traditional: true,
                    success: function (data) {
                        if(data.errorCode == "15002"){
                            myNotify("error", "", "该角色超过最大可创建数据量，请联系管理员！");
                        }else{
                            myNotify("success", "", "修改成功");
                            $('#modal_modify_account').modal('hide');
                            refreshJQGrid( $('#AccountJQGrid').jqGrid('getGridParam','page'));
                        }

                    },
                    error: function () {
                            myNotify("error", "", "修改组织提交过程中发生错误，请联系管理员！");
                    }
                });
            } else {
                    myNotify("error", "", "请更正错误后在进行提交");
            }
            return false;
        })
    })

    /******************************方法声明**********************************/
    function stopOrganize($this, id, orgId, roleId) {
        if ($($this).attr('alt') == "启用") {
            businessEnable($this, id, orgId, roleId)
        } else {
            businessDisable($this, id)
        }
    }
    function txt_myorg_cbs() {
        var formData = new FormData();
        formData.append("orgId", $("#txt_myorg").val());
        $.ajax({
            url: '<%=basePath%>/account/getBusinessTemplate.do',
            type: 'POST',
            data: formData,
            async: false,
            // 这两个参数需要被定义，否则报错
            contentType: false,
            processData: false,
            traditional: true,
            success: function (data) {
                  var  $txt_business_template= $('#txt_business_template');
                $txt_business_template.empty();
                $.each(data.list, function (a, b) {
                    $txt_business_template.append("<option value='" + b.id + "'>" + b.templateName + "</option>")
                })
                $txt_business_template.selectpicker('refresh');

                if($("[name='inlineRadioOptions']:checked").val() == "3"){
                    $txt_business_template.selectpicker('selectAll');
                    $txt_business_template.prop("disabled",true).blur();
                }else{
                    $txt_business_template.selectpicker('deselectAll');
                    $txt_business_template.prop("disabled",false).blur();
                }
                $txt_business_template.selectpicker('refresh');
            },
            error: function () {
                myNotify("error", "", "查询相关模板过程中发生错误，请联系管理员！");
            }
        });
    }
    function businessDisable(obj, id) {
        bootbox.confirm({
            message: "是否停止当前选中账户，停止后该账户人员无法使用？",
            buttons: {
                confirm: {
                    label: '确认',
                    className: 'btn-success'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result) {
                    var command = "disable";
                    accountOperate(obj, id, command);
                }
            }
        });
    }


    function businessEnable(obj, id, orgId, roleId) {
        bootbox.confirm({
            message: "是否启用当前账户，启用后该账户可使用？",
            buttons: {
                confirm: {
                    label: '确认',
                    className: 'btn-success'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result) {
                    var command = "enable";
                    accountOperate(obj, id, command, orgId, roleId);
                }
            }
        });
    }

    function accountOperate(obj, id, command, orgId, roleId) {
        $.ajax({
            url: "<%=basePath%>/account/accountOperate.do",
            type: "post",
            async: true,
            data: "id=" + id + "&command=" + command + "&orgId=" + orgId + "&roleId=" + roleId,
            dataType: "json",
            success: function (data) {
                if (data["errorCode"] == "0") {
                    myNotify("success", "", "操作成功");
                } else {
                    myNotify("error", "", data["msg"]);
                }
                refreshJQGrid($('#AccountJQGrid').jqGrid('getGridParam','page'));
            },
            error: function (data) {
                    myNotify("error", "", "操作请求发送过程中发生错误，请尽快联系管理员！");
            }
        });
    }
    function refreshJQGrid(mpage) {
        //刷新页面表格数据 没页面数默认为第一页。
            mpage=$.isNumeric(mpage)?mpage:1;
            var txt_user_name = $.trim($("#txt_user_name").val());
            if(txt_user_name.length > 0){
                if(!/^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(txt_user_name)){
                    myNotify("error", "", "用户名称不存在");
                    return false;
                }
            }
        var postData = $('#AccountJQGrid').jqGrid("getGridParam", "postData");
        $.each(postData, function (k, v) {
            delete postData[k];
        });
        $("#AccountJQGrid").jqGrid("setGridParam", {
            url: "<%=basePath %>/account/fetchUserInfoJQGridDataByConditions.do",
            mtype: 'POST',
            datatype: "json",
            postData: getFilterData(),
            page: mpage
        }).trigger("reloadGrid");
    }
        function getFilterData() {
            //设置提交数据
            var postData = {};
            var txt_user_name = $("#txt_user_name").val();
            var txt_role_power = $("#txt_role_power").val();
            var txt_org = $("#txt_org").val();
            var txt_state_account = $("#txt_state_account").val();
            var txt_business = $("#txt_business").val();
            if (!isEmpty(txt_role_power)) {
                postData.roleId=txt_role_power;
            }
            if (!isEmpty(txt_org)) {
                postData.orgId=txt_org;
            }
            if (!isEmpty(txt_state_account)) {
                postData.status=txt_state_account;
            }
            if (!isEmpty(txt_business)) {
                postData.templateId=txt_business;
            }
            postData.username=txt_user_name;
            return postData;
        }

    function getChecked() {
        var tasks = "";
        $("#ck_tasks").find("input").each(function () {
            if (tasks != "" && $(this).prop("checked")) {
                tasks += ","
            }
            if ($(this).prop("checked")) {
                tasks += $(this).attr("value").trim();
            }
        });
        return tasks;
    }
    var activeUser=null;//编辑的用户信息
    function editAccount($this, id) {
        //编辑框设置
        $("#userName,#userId").html("");
        $("#showChangepwd").closest(".form-group").show();
        $(".changePwd,.confirmPwd").addClass("hide");
        $("#form_modify_pwd")[0].reset();
        $('#txt_myorg').selectpicker('refresh');
        $('#txt_myorg').selectpicker('deselectAll');
        var selData = $("#AccountJQGrid").jqGrid('getRowData', id);
        activeUser=selData;
        $("#userName").html(selData.u_name);
        $("#userId").html(selData.user_id);
        $("#createTime").html(selData.create_time);
        $("[name='inlineRadioOptions'][value='" + selData.role_id + "']").prop("checked", true);

        if(selData.role_id == "2"){
            $(".yuAdmin").show().siblings().hide();

        }else if(selData.role_id == "3"){
            $(".yuAdmin").hide().siblings().show();
        }else{
            $(".yuAdmin").hide().siblings().show();
//            if(selData.templateId!=null){
//
//            }
        }
//        $.each(AccountJQGriddata.dataList, function (index, item) {
//            if (item.user_id == id) {
//                console.log(item)
//                activeUser=item;
//                $("#userName").html(item.u_name);
//                $("#userId").html(item.user_id);
//                $("#createTime").html(item.create_time);
//                $("[name='inlineRadioOptions'][value='" + item.role_id + "']").prop("checked", true);
//
//                if(item.role_id == "2"){
//                    $(".yuAdmin").show().siblings().hide();
////                    $('#txt_myorg').prop("disabled",false).selectpicker('refresh');
////                    $('#txt_myorg').closest(".form-group").hide();
//                }else if(item.role_id == "3"){
//                    $(".yuAdmin").hide().siblings().show();
////                    $('#txt_myorg').closest(".form-group").show();
////                    $('#txt_myorg').prop("disabled",true).selectpicker('val', item.org_id);
////                    txt_myorg_cbs();
//                }else{
//                    $(".yuAdmin").hide().siblings().show();
////                    $('#txt_myorg').closest(".form-group").show();
////                    $('#txt_myorg').prop("disabled",true).selectpicker('val', item.org_id);
////                    txt_myorg_cbs();
//                    if(item.templateId!=null){
//
//                    }
//                }
//                return false;
//            }
//        });
//        $('#txt_myorg').selectpicker('refresh');
        $("#modal_modify_account").modal({
            backdrop: false,
            keyboard: false
        });
        $("#form_modify_pwd .has-error").removeClass("has-error");
        $("#form_modify_pwd .redBorder").removeClass("redBorder");
        vaildateform();
    }

    function vaildateform() {
        if (fmp != null) {
            fmp.destroy();
            fmp = null;
        }

        fmp = $("#form_modify_pwd").validate({
            errorPlacement: function (error, element) {
                // Append error within linked label
                //console.log(element)
                $(element)
                    .closest("div.form-group")
                    .find("span.help-block")
                    .append(error);
            },
            errorElement: "p",
            rules: {
                txt_account_passwd: {
                    required: true,
                    isPassword2: true,
                    isRangelen: [6, 16]

                },
                txt_confirm_passwd: {
                    required: false,
                    equalTo: "#txt_account_passwd"
                },
                inlineRadioOptions: {
                    required: true
                },
                txt_myorg: {
                    required: true
                },
                txt_business_template: {
                    required: true
                }
            },
            messages: {
				txt_account_passwd: {
                    required: "密码称不能为空，请输入密码",
                    isPassword2: "字符或格式有误，请输入6-16个字符，只能包含字母、数字以及标点符号，至少包含2种字符类型",
                    minlength: "至少输入6位字符",
				},
                txt_confirm_passwd: {
                    equalTo: "密码输入不一致"
                },
                inlineRadioOptions: {
                    required: "权限角色不能为空"
                },
                txt_myorg: {
                    required: "所属组织不能为空"
                },
                txt_business_template: {
                    required: "业务模板不能为空"
                }
            }
        });
    }
</script>
</body>
</html>